
package com.yimixian.app.ui;

import com.yimixian.app.R;
import com.yimixian.app.model.PullMessage;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.TextView;

import butterknife.ButterKnife;
import butterknife.InjectView;

public class PullMessageView extends FrameLayout {

    @InjectView(R.id.title_text)
    TextView mTitleText;
    @InjectView(R.id.content_text)
    TextView mContentText;
    @InjectView(R.id.confirm_text)
    TextView mConfirmText;
    @InjectView(R.id.check_text)
    TextView mCheckText;

    public PullMessageView(Context context) {
        super(context);
        initPullMessageView();
    }

    public PullMessageView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initPullMessageView();
    }

    public PullMessageView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initPullMessageView();
    }

    private void initPullMessageView() {
        LayoutInflater.from(getContext()).inflate(R.layout.push_message_view, this);
        ButterKnife.inject(this);
        setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (PullMessageView.this.getParent() != null) {
                    ((ViewGroup) PullMessageView.this.getParent()).removeView(PullMessageView.this);
                }
            }
        });
    }

    public void bind(final PullMessage pullMessage, OnClickListener onConfirmTextClick,
            OnClickListener onCheckTextClick) {
        mTitleText.setText(pullMessage.title);
        mContentText.setText(pullMessage.desc);
        mConfirmText.setOnClickListener(onConfirmTextClick);
        if (onCheckTextClick != null) {
            mCheckText.setOnClickListener(onCheckTextClick);
        } else {
            mCheckText.setVisibility(View.GONE);
        }
    }
}
